<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Restoring Log Files</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Getting Started with Berkeley DB, Java Edition High Availability Applications" />
    <link rel="up" href="utilities.html" title="Chapter 4. Utilities" />
    <link rel="prev" href="utilities.html" title="Chapter 4. Utilities" />
    <link rel="next" href="dbbackup.html" title="Backing up a Replicated Application" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Restoring Log Files</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="utilities.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 4. Utilities</th>
          <td width="20%" align="right"> <a accesskey="n" href="dbbackup.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="logfile-restore"></a>Restoring Log Files</h2>
          </div>
        </div>
      </div>
      <p>
            During normal operations, the nodes in a replication group
            communicate with one another to ensure that the JE cleaner
            does not reclaim log files still needed by the group. The tail
            end of the replication stream may still be needed by a lagging
            Replica in order to make it current with the Master, and so the
            replication group makes sure the trailing log files needed to
            bring lagging Replicas up-to-date are not reclaimed.
        </p>
      <p>
            However, if a node becomes unavailable for a long enough period
            of time, then log files needed to bring it up to date will be
            reclaimed by the cleaner. The length of time that a node is
            unavailable before necessary log files are reclaimed is defined
            by <a class="ulink" href="../java/com/sleepycat/je/rep/ReplicationConfig.html#REP_STREAM_TIMEOUT" target="_top">REP_STREAM_TIMEOUT</a> property, which you can manage using 
            <a class="ulink" href="../java/com/sleepycat/je/rep/ReplicationConfig.html#setConfigParameter(java.lang.String,java.lang.String)" target="_top">ReplicationConfig.setConfigParameter()</a>. The default value is 24
            hours.
        </p>
      <p>
            Once log files have been reclaimed by a cleaner, then the
            Replica can no longer be brought up to date using the normal
            replication stream. Your application code will know this has
            happened when the <a class="ulink" href="../java/com/sleepycat/je/rep/ReplicatedEnvironment.html" target="_top">ReplicatedEnvironment</a> constructor throws
            an <a class="ulink" href="../java/com/sleepycat/je/rep/InsufficientLogException.html" target="_top">InsufficientLogException</a>.
        </p>
      <p>
            When your code catches an <a class="ulink" href="../java/com/sleepycat/je/rep/InsufficientLogException.html" target="_top">InsufficientLogException</a>, then you
            must bring the Replica up-to-date using a mechanism other than
            the normal replication stream. You do this using the
            <a class="ulink" href="../java/com/sleepycat/je/rep/NetworkRestore.html" target="_top">NetworkRestore</a> class. A call to <a class="ulink" href="../java/com/sleepycat/je/rep/NetworkRestore.html#execute(com.sleepycate.je.rep.InsufficientLogException,com.sleepycat.je.rep.NetworkRestoreConfig)" target="_top">NetworkRestore.execute()</a>
            causes the Replica to copy the missing log files from a member
            of the replication group who owns the files and seems to be the
            least busy. Once the Replica has obtained the log files that it
            requires, it automatically re-establishes its replication stream 
            with the Master so that the Master can finish bringing the
            Replica up-to-date.
        </p>
      <p>
            For example:
        </p>
      <pre class="programlisting"> ...
  try {
     node = new ReplicatedEnvironment(envDir, repConfig, envConfig);
 } catch (InsufficientLogException insufficientLogEx) {

     NetworkRestore restore = new NetworkRestore();
     NetworkRestoreConfig config = new NetworkRestoreConfig();
     config.setRetainLogFiles(false); // delete obsolete log files.

     // Use the members returned by insufficientLogEx.getLogProviders() 
     // to select the desired subset of members and pass the resulting 
     // list as the argument to config.setLogProviders(), if the 
     // default selection of providers is not suitable.

     restore.execute(insufficientLogEx, config);

     // retry
     node = new ReplicatedEnvironment(envDir, repConfig, envConfig);
 } ...  </pre>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="utilities.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="utilities.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="dbbackup.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Chapter 4. Utilities </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Backing up a Replicated Application</td>
        </tr>
      </table>
    </div>
  </body>
</html>
